home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / stdio / c / rename < prev    next >
Text File  |  1996-11-09  |  1KB  |  52 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/stdio/c/RCS/rename,v $
  4.  * $Date: 1996/05/06 09:01:34 $
  5.  * $Revision: 1.2 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: rename,v $
  10.  * Revision 1.2  1996/05/06 09:01:34  unixlib
  11.  * Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
  12.  * Saved for 3.7a release.
  13.  *
  14.  * Revision 1.1  1996/04/19 21:32:42  simon
  15.  * Initial revision
  16.  *
  17.  ***************************************************************************/
  18.  
  19. static const char rcs_id[] = "$Id: rename,v 1.2 1996/05/06 09:01:34 unixlib Rel $";
  20.  
  21. #include <stdio.h>
  22. #include <ctype.h>
  23. #include <unistd.h>
  24.  
  25. __STDIOLIB__
  26.  
  27. int
  28. rename (const char *old, const char *new)
  29. {
  30.   {
  31.     register const char *s1 = old, *s2 = new;
  32.     register int c1, c2;
  33.  
  34.     while (c1 = *s1++, c2 = *s2++)
  35.       {
  36.     if (isupper (c1))
  37.       c1 = _tolower (c1);
  38.     if (isupper (c2))
  39.       c2 = _tolower (c2);
  40.     if (c1 != c2)
  41.       break;
  42.       }
  43.     if (c1 != c2)
  44.       unlink ((char *) new);
  45.   }
  46.  
  47.   if (link ((char *) old, (char *) new))
  48.     return (-1);
  49.  
  50.   return (0);
  51. }
  52.